class Solution
{
public:
    bool verifyTreeOrder(vector<int>& postorder)
    {
        stack<int> stk;
        int root = 0x3f3f3f;
        for (int i = postorder.size() - 1; i >= 0; i--)
        {
            if (postorder[i] > root) return false;
            while (!stk.empty() && stk.top() > postorder[i])
            {
                root = stk.top();
                stk.pop();
            }
            stk.push(postorder[i]);
        }
        return true;
    }
};
